using UnityEngine;

using UnityEngine.Events;

namespace Geo.DizzyLab
{
    public class PassthroughController : MonoBehaviour
    {
        public Camera normalCamera;
        public GameObject passthroughObject;

        public UnityEvent onPassthroughEnabled, onPassthroughDisabled;

        /// <summary>
        /// 获取或设置透视状态。
        /// true - 透视开启
        /// false - 透视关闭
        /// </summary>
        public bool PassthroughEnabled
        {
            set
            {
                if (value == PassthroughEnabled)
                    return;
                // 禁止或开启透视
                passthroughObject.SetActive(value);
                // 开启或禁止正常相机
                normalCamera.enabled = !value;
                //
                if (value == true)
                    onPassthroughEnabled.Invoke();
                else
                    onPassthroughDisabled.Invoke();
            }
            get => !normalCamera.enabled;
        }
        /// <summary>
        /// 切换透视状态。
        /// </summary>
        public void TogglePassthrough() => PassthroughEnabled = !PassthroughEnabled;
    }
}
